package flex.cc.sms.service;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import flex.cc.order.manage.dto.order.OrderMainEntity;
import flex.cc.order.manage.service.OrderMainService;


/**
 * 
 * @author WANGCONG
 * 2021年11月3日上午10:13:52
 * @desc 短信发送异步接口
 */
@Service
public class SendSmsService {

	private static final Logger logger = LoggerFactory.getLogger(SendSmsService.class);
	@Resource
	private SmsInfoService smsInfoService;
	@Resource
	private OrderMainService orderMainService;
	
	/**
	 * 
	 * @author WANGCONG
	 * 2021年11月3日上午10:16:08
	 * @desc 短信异步发送
	 */
	@Async
	public void sendSms(String orderNo) {
		logger.info("--------------------进入短信发送接口--------------------");
		Map<String, Object> param = new HashMap<>();
		param.put("orderNo", orderNo);
		OrderMainEntity currentOrderMain = orderMainService.getOneByParams(param);
		String status = currentOrderMain.getStatus();
		if ("02".equals(status) || "04".equals(status) || "05".equals(status) || "08".equals(status)) { // 02-已受理、04已接单、05-开始出发。08-已完成
			Map<String, Object> sendSms = smsInfoService.send(currentOrderMain);
			String responseCode = sendSms.get("responseCode").toString();
			String responseMsg = sendSms.get("responseMsg").toString();
			if ("00".equals(responseCode)) { // 短信发送成功
				logger.info(orderNo+"----短信发送成功--------------------");
			} else {
				logger.info(orderNo+"----短信发送失败----原因="+responseMsg);
			}
		}
	}
	
	
}
